Skip to content

Change reveal_type() representation of TypedDicts#3598

Merged
JukkaL merged 5 commits into
masterfrom
typeddict-repr
Jul 4, 2017
Merged

Change reveal_type() representation of TypedDicts#3598
JukkaL merged 5 commits into
masterfrom
typeddict-repr

Conversation

@JukkaL

@JukkaL JukkaL commented Jun 23, 2017

Copy link
Copy Markdown
Collaborator

Change the formatting to be closer to the TypedDict definition syntax
and preserve TypedDict name when constructing using TD(...) for better
reveal_type output.

Note that this uses a new representation 'key'?: type for
non-required keys.

I'll update remaining error messages to use the new syntax in a
separate PR.

Fixes #3590.

Change the formatting to be closer to the TypedDict definition syntax
and preserve TypedDict name when constructing using TD(...) for better
reveal_type output.

Note that this uses a new representation `'key'?: type` for
non-required keys.

I'll update remaining error messages to use the new syntax in a
separate PR.

Fixes #3590.
JukkaL added a commit that referenced this pull request Jun 23, 2017
Distinguish between required and non-required keys and use
syntax that is closer to TypedDict definition syntax.

This is follow-up to #3598.
@gvanrossum gvanrossum requested a review from ilinum June 26, 2017 18:49

@ilinum ilinum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good!

The output of reveal_type is so much nicer with this PR!

Comment thread mypy/checkexpr.py
fallback = self.chk.named_generic_type('typing.Mapping',
[self.chk.str_type(), mapping_value_type])
return TypedDictType(items, set(callee.required_keys), fallback)
return callee

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you do not create a new TypedDictType anymore?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, is that in order to preserve the original TypedDict name?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Also, the deleted code no longer serves its original purpose because of changes to TypedDict type inference.

[builtins fixtures/dict.pyi]
[out1]
main:2: error: Revealed type is 'TypedDict(x=builtins.int, y=builtins.str, _fallback=m.D, _total=False)'
main:2: error: Revealed type is 'TypedDict('m.D', {'x'?: builtins.int, 'y'?: builtins.str})'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think while the ?-syntax for non-required keys has its downsides, it works well in this case.
We need to be concise and I think ? is pretty intuitive.
It might be worth mentioning it documentation.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good point. I'll update the docs tomorrow to mention ?.

ilinum pushed a commit that referenced this pull request Jun 27, 2017
Distinguish between required and non-required keys and use
syntax that is closer to TypedDict definition syntax.

This is follow-up to #3598.
@JukkaL JukkaL merged commit b3b9790 into master Jul 4, 2017
@gvanrossum gvanrossum deleted the typeddict-repr branch July 5, 2017 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve representation of TypedDicts

2 participants